//|||||||||||||||||||||||||||||||||||||||||||||||

#ifndef GAME2_STATE_HPP
#define GAME2_STATE_HPP

//|||||||||||||||||||||||||||||||||||||||||||||||

#include "AppState.hpp"

#include "DotSceneLoader.hpp"

#include <OgreSubEntity.h>
#include <OgreMaterialManager.h>

//|||||||||||||||||||||||||||||||||||||||||||||||

const float PLAYER2_OFFSET = 1.5f;
const float PLAYER2_HEIGHT = 7.0f;
const float SECTION_LENGTH = 100.0f;
const float SECTION_X_PATH_BEGIN = 23.4f;
const float SECTION_X_PATH_END = 44.4f;
const float PROGRESS2_PER_MILISECOND = -0.000002f;
const float PROGRESS2_PER_BONUS = 0.05f;
const float PROGRESS2_PER_HAZARD = -0.05f;

//|||||||||||||||||||||||||||||||||||||||||||||||

class Game2State : public AppState
{
public:
	Game2State();

	DECLARE_APPSTATE_CLASS(Game2State)

	void enter();
	void createScene();
	void exit();
	bool pause();
	void resume();

	void moveCamera(double timeSinceLastFrame);
	void getInput();
    void buildGUI();

	bool keyPressed(const OIS::KeyEvent &keyEventRef);
	bool keyReleased(const OIS::KeyEvent &keyEventRef);

	bool mouseMoved(const OIS::MouseEvent &arg);
	bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id);

	void onLeftPressed(const OIS::MouseEvent &evt);
    void itemSelected(OgreBites::SelectMenu* menu);

	void update(double timeSinceLastFrame);

	
	void updateHazardsAndBonusesCollisions();
	void checkVictoryOrLose();
	Ogre::SceneNode* checkCollisionWithHazards(Ogre::AxisAlignedBox &box);
	Ogre::SceneNode* checkCollisionWithBonuses(Ogre::AxisAlignedBox &box);

	void checkBorderCollision();
	void checkBorderCollision(Ogre::SceneNode* currentSection,
		Ogre::Vector3 &playerPosition,
		Ogre::Vector3 parentPosition,
		float angle);

private:
	bool						m_bQuit;
	float						angleSR;
	float						angleR;
	float						angleSL;
	float						angleL;

//	long						timeSinceAPressed;
//	long						timeSinceDPressed;

	float						playerSpeed;
	float						maxPlayerSpeed;
	float						progressBarState;
	float						progressBarSpeed;
	float						progressBarValue;
	bool						buttonA;
	bool						buttonB;

	bool						playerFalling;
	float						playerSpeedY;
	OgreBites::ProgressBar*		bar;

	void						winGame();
	void						loseGame();
	OgreBites::ProgressBar*		timeLeftBar;
	bool						won;
};

//|||||||||||||||||||||||||||||||||||||||||||||||

#endif

//|||||||||||||||||||||||||||||||||||||||||||||||